import 'package:flutter/material.dart';



// 按钮组
class CustomButtonBar extends StatefulWidget {

  final dynamic children; // 内容


  CustomButtonBar({
    Key key,
    this.children,
  }) : super(key: key);  

  @override
  _CustomButtonBarState createState() => new _CustomButtonBarState();
}

class _CustomButtonBarState extends State<CustomButtonBar> {


    // 按钮组
    Widget _bodyInit() {

      if( widget.children!=null ){
        
        List _child=widget.children;
        List<Widget> _list = [];

        // Widget content; 
        for(var i = 0; i < _child.length; i++){
          _list.add(
            MaterialButton(
                color: _child[i]["color"]!=null?_child[i]["color"]:Colors.blue,
                textColor: Colors.white,
                child: Text( _child[i]["text"]!=null?_child[i]["text"].toString():"" ),
                onPressed: () {
                  if( _child[i]["onClick"]!=null ){
                    _child[i]["onClick"]();
                  }
                },
            )         
          );
        }

        return ButtonBar(
          children: _list.toList(),
        );
      }

      return null;
    }

    @override
    Widget build(BuildContext context) {
      return Container(
        child: _bodyInit(),
      );                
    }
}